﻿using NewRen.Log4net;
using NewRen.Schemas;
using PagedList;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NewRen.Areas.Admin.Controllers
{
    [Schema.LoginCheck]
    public class LogController : BaseController
    {
        // GET: Admin/Log
        public ActionResult Index(int page = 1)
        {
            return View(db.Logs.OrderByDescending(l => l.AddTime).ToPagedList(page, 20));
        }


        /// <summary>
        /// 删除日志
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [ValidateSID]
        [HttpPost]
        public ActionResult LogDelete(int id)
        {
            try
            {
                var log = db.Logs.Find(id);
                db.Logs.Remove(log);
                db.SaveChanges();
                return Content("ok");
            }
            catch(Exception ex)
            {
                log.Error(new LogContent("删除版主失败", Helpers.HttpHelper.GetIPAddress()), ex);
                return Content("err");
            }
        }

        [HttpGet]
        public ActionResult Show(int id)
        {
            var log = db.Logs.Find(id);
            return View(log);
        }
    }
}